import { useCallback, useEffect } from 'react';
import '@/assets/styles/global.scss';
import Editform from './Editform';
import { request, request4 } from '@/store/modules/doctor';
import { useDispatch, useSelector } from 'react-redux';
import type { StoreState, StoreDispatch } from '@/store';
import { useLocation } from 'react-router-dom';

export default function DoctorEdit() {
    const {
        state: { record },
    } = useLocation();
    // 获取仓库状态
    const dispatch: StoreDispatch = useDispatch();
    const editdata = useSelector((state: StoreState) => state.doctor.editdata);

    const getTabData = useCallback(async () => {
        await dispatch(request());
    }, [dispatch]);

    const getEditData = useCallback(async () => {
        const res = record.key.split()
        await dispatch(request4({ id: res }));
    }, [dispatch,record]);


    console.log(record);
    console.log(editdata);

    useEffect(() => {
        getTabData();
        getEditData();
    }, [getTabData, getEditData]);

    return (
        <>
            <div className="header">
                <div className="div1">
                    <div className="icon"></div>
                    <span>编辑医生信息</span>
                </div>

                <div className="div2"></div>
            </div>
            <Editform getTabData={getTabData} record={record}/>
        </>
    );
}
